-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of def-use chain #156
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase the latest master
branch to resolve CI breakage.
I would like to ask @fennecJ for reviewing. |
Can you provide test cases accordingly? |
Do you mean adding test cases in |
Yes, it makes sense. |
99d2dac
to
d9e48c9
Compare
Implement a new structure for def-use chain called "use_chain_t". "use_chain_t" is stored within "struct var", includes "insn" element that records the instruction using the variable which the use chain belongs to. Simplify CSE procedure with use chain information. We build the def-use chain information by "build_users" function before the optimizing phase. In addtion, When the instructions are eliminated by CSE, we delete its use chain nodes from both variables("rs1", "rs2") at the same time. The CSE method has been modified. When the first pair of instructions is found, the use chain is utilized to search for identical ADD instructions. Subsequently, the next instruction is verified to ensure it match our target. After removing the instruction, utilize the use chain to find the next target instruction. Use the following code as an example. Note that it should be compiled with option "--no-libc" and the DCE should be disabled. ``` int main() { char arr[1]; int i, t, pos = 0; for (i = 0; i < 10000000; i++) t = arr[pos] + arr[pos]; return 0; } ``` The difference between before and after CSE: ``` ldr r0, [sp, sysprog21#4] ldr r1, [sp, sysprog21#9] add r2, r0, r1 ldrb r3, [r2] -add r2, r0, r1 -ldrb r4, [r2] +mov r2, r3 ```
Thank @nosba0957 for contributing! |
Apologies, I just reviewed the PR and was preparing my response. The functionality looks correct, and the generated binary code matches the original implementation based on my offline tests. However, I have a concern about the simplification—it doesn’t seem to achieve the expected level of simplification. Nevertheless, I believe the DU-chain implementation can still be useful in the future for further optimizations. Additionally, I think it’s important to properly clean up the allocated memory when constructing the DU-chain at the end of the compilation process. |
No problem. Create another GitHub issue for tracking. |
Implement a new structure for def-use chain called
uc_node_t
.uc_node_t
is stored withinstruct var
, includesinsn
element that records the instruction using the variable which the use chain belongs to.Simplify CSE procedure with use chain information. We build the def-use chain information by
build_use_chain
function before the optimizing phase. In addtion, When the instructions are eliminated by CSE, we delete its use chain nodes from both variables(rs1
,rs2
) at the same time.The CSE method has been modified. When the first pair of instructions is found, the use chain is utilized to search for identical ADD instructions. Subsequently, the next instruction is verified to ensure it match our target. After removing the instruction, utilize the use chain to find the next target instruction.
resolve #155